package com.cabrida.livestar.main.me;

import java.util.ArrayList;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cabrida.livestar.R;
import com.cabrida.livestar.model.FansVLogData;
import com.cabrida.livestar.util.MyUtils;
import com.cabrida.livestar.view.CircleImageView;

/**
 * 我的关注adapter
 * 
 * @author why
 * 
 */
public class AttentionGvAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<FansVLogData> data_list = new ArrayList<FansVLogData>();

	public AttentionGvAdapter(Context context) {
		this.mInflater = LayoutInflater.from(context);
	}

	public void setData(ArrayList<FansVLogData> data) {
		data_list = data;
	}

	@Override
	public int getCount() {
		return data_list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return data_list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(
					R.layout.adapter_attention_gv_item, null);
			holder.iv_header = (CircleImageView) convertView.findViewById(R.id.iv_header);
			holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
			holder.iv_live = (ImageView) convertView.findViewById(R.id.iv_live);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();

		}
		
		FansVLogData data = data_list.get(position);
		holder.tv_name.setText(data.getS_name());
		MyUtils.loadImg(data.getU_avatar(), holder.iv_header);
		if (!TextUtils.isEmpty(data.getLive())){
			int live_int = Integer.valueOf(data.getLive());
			if (live_int > 0) {
				holder.iv_live.setVisibility(View.VISIBLE);
			}else {
				holder.iv_live.setVisibility(View.INVISIBLE);
			}
		}

		return convertView;
	}

	class ViewHolder {
		private CircleImageView iv_header;
		private TextView tv_name;
		private ImageView iv_live;
	}

}
